package control;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import Dao.UserDao;
import Dao.UserDaoimpl;
import Dao.WordDaoimpl;
import entity.User;
import entity.Word;
import service.WordService;
import service.WordServiceimpl;

/**
 * Title: 
 * Description: 主页搜索单词
 * @author: 张文涛
 * @date: 2021年1月7日,下午2:38:16
 */
public class Getwords extends HttpServlet{
	WordService ws = new WordServiceimpl();
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doGet(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("post words");
		String word = req.getParameter("word");
		System.out.println(word);
		req.setCharacterEncoding("utf-8");
		List<Word> l = null;
		if(word==null) {
			return;
		}
		try {
			l = ws.searchByname(word,5);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		resp.setCharacterEncoding("utf-8");
		System.out.println("words send");
		resp.getWriter().print(JSON.toJSONString(l));
	}	
}
